<!DOCTYPE html>
<html lang="en">
  <head>
    <title>RWLock Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../../js/jquery.min.js" defer></script>
    <script src="../../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/RWLock" class="dashAnchor"></a>
    <a title="RWLock Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../../index.html"> Docs</a> (100% documented)</p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../../index.html"> Reference</a>
        <img id="carat" src="../../img/carat.png" />
        RWLock Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Protocols/ThreadQueue.html">ThreadQueue</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../../Structs.html">Structs</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Structs/Threading.html">Threading</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Structs/Threading/Lock.html">– Lock</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Structs/Threading/Event.html">– Event</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Structs/Threading/RWLock.html">– RWLock</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Structs/Threading/QueueType.html">– QueueType</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>RWLock</h1>
              <div class="declaration">
                <div class="language">
                  <pre class="highlight"><code><span class="kd">public</span> <span class="kd">final</span> <span class="kd">class</span> <span class="kt">RWLock</span></code></pre>

                </div>
              </div>
            <p>A read-write thread lock.
Permits multiple readers to hold the while, while only allowing at most one writer to hold the lock.
For a writer to acquire the lock all readers must have unlocked.
For a reader to acquire the lock no writers must hold the lock.</p>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLockcFT_S1_"></a>
                    <a name="//apple_ref/swift/Method/init()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLockcFT_S1_">init()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Initialize a new read-write lock.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock8readLockFT_Sb"></a>
                    <a name="//apple_ref/swift/Method/readLock()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock8readLockFT_Sb">readLock()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Attempt to acquire the lock for reading.
Returns false if an error occurs.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">readLock</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock11tryReadLockFT_Sb"></a>
                    <a name="//apple_ref/swift/Method/tryReadLock()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock11tryReadLockFT_Sb">tryReadLock()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Attempts to acquire the lock for reading.
Returns false if the lock is held by a writer or an error occurs.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">tryReadLock</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock9writeLockFT_Sb"></a>
                    <a name="//apple_ref/swift/Method/writeLock()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock9writeLockFT_Sb">writeLock()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Attempt to acquire the lock for writing.
Returns false if an error occurs.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">writeLock</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock12tryWriteLockFT_Sb"></a>
                    <a name="//apple_ref/swift/Method/tryWriteLock()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock12tryWriteLockFT_Sb">tryWriteLock()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Attempt to acquire the lock for writing.
Returns false if the lock is held by readers or a writer or an error occurs.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">tryWriteLock</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock6unlockFT_Sb"></a>
                    <a name="//apple_ref/swift/Method/unlock()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock6unlockFT_Sb">unlock()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Unlock a lock which is held for either reading or writing.
Returns false if an error occurs.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">unlock</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock14doWithReadLockFzFzT_T_T_"></a>
                    <a name="//apple_ref/swift/Method/doWithReadLock(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock14doWithReadLockFzFzT_T_T_">doWithReadLock(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Acquire the read lock, execute the closure, release the lock.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">doWithReadLock</span><span class="p">(</span><span class="nv">closure</span><span class="p">:</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="p">())</span> <span class="k">rethrows</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCV13PerfectThread9Threading6RWLock15doWithWriteLockFzFzT_T_T_"></a>
                    <a name="//apple_ref/swift/Method/doWithWriteLock(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCV13PerfectThread9Threading6RWLock15doWithWriteLockFzFzT_T_T_">doWithWriteLock(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Acquire the write lock, execute the closure, release the lock.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">doWithWriteLock</span><span class="p">(</span><span class="nv">closure</span><span class="p">:</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="p">())</span> <span class="k">rethrows</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2016 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2016-06-16)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.0</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
